Release 10.1A: OpenEdge Getting Started:
Object-oriented Programming


Data member scoping in classes and procedures

Classes support the same definitions for variables, buffers, queries, temp-tables, and ProDataSets as procedures do, with one difference. That difference is the access modifier PRIVATE, PUBLIC, or PROTECTED. Because of this difference, these built-in types are referred to as data members when they are used in classes. For more information on what access modes are valid for each type of data member definition, see the "Defining data members within a class" section. By default, all data members are PRIVATE.

As with methods, the PROTECTED option lets you define data members accessible throughout the class hierarchy but not from outside it. It also lets you use data member definitions throughout the hierarchy without having to repeat the definitions in each class that uses them.

Comparison with procedure-based programming

Variables and other types of data definitions are also implicitly PRIVATE when used in procedures. You can achieve something like the PROTECTED capability using procedures by defining variables and other types of data as NEW SHARED in a parent procedure and as SHARED in a subprocedure. Shared data elements require that the definitions be repeated as SHARED in each subprocedure that shares them, which is typically done using an include file containing all of the definitions, so that they are guaranteed to match in all procedures that use them. You can achieve something similar to PUBLIC data members using GLOBAL SHARED variables and other data elements, with the key difference that while PUBLIC data members are scoped to the class that defines them, once a variable or other data element is defined as GLOBAL SHARED it remains allocated for the duration of the session and cannot be deleted.


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095